#include "RobotProject.h"
#include <string.h>

RobotProject::RobotProject()
{
	numRobots=0;
}

RobotProject::~RobotProject()
{

}

bool RobotProject::appendRobot(Robot* robot)
{	
	if(this->numRobots<MAX_ROBOTS)
		robotArray[numRobots++] = robot;
	
	else
		return false;
	return true;
}

bool RobotProject::removeRobot(int index)
{
	if(index<numRobots && index>=0)
	{
		//delete robot
		Robot* robot = robotArray[index];
		cout<<"name of robot "<<robot->getName()<<endl;
		delete robot;
		//organize robot array
		for(int i = index; i<numRobots;i++)
		{
			robotArray[i] = robotArray[i+1]; 
		}
		numRobots--;
		return true;
	}
	else
		return false;
}

int RobotProject::getRobotIndex(char* name)
{
	for(int i=0; i<numRobots;i++)
	{
		Robot* robot = robotArray[i];
		if(!strcmp(name,robot->getName()))
			return i;
	}
	return -1;
}

bool RobotProject::removeRobot(char* name)
{
	int i = getRobotIndex(name);
	return removeRobot(i);
}
